<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>忘记密码</title>
  <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
  <script src="<%=path%>/resource/core/wechat/jweixinapi.js"></script>
  <jsp:include page="../../../main/mp/inc.jsp"	/>
  <script>
    var countdown=120;
    function settime(btn) {
      if (countdown == 0) {
        btn.attr("value","获取验证码");
        btn.text("获取验证码");
        btn.attr( "disabled",false );
        countdown = 120;
      } else {
        btn.attr("value","重新发送(" + countdown + ")");
        btn.text("重新发送(" + countdown + ")");
        btn.attr( "disabled",true );
        countdown--;
        setTimeout(function() {
          if (countdown >= 0) {
            settime(btn)
          }
        },1000)
      }
    }

    $(function(){
      $('#btn-get-code').click(function(e){
        $("#message_alert").empty();
        $("#message_alert").html("正在发送...");
        $.ajax({
          type: "POST",
          url: "sendAuthCode",
          cache:false,dataType:"json",async:true,
          data: $("form#form-common").serialize(),
          success: function(data){
            $("#message_alert").empty();
            if(data.state == 1 ){
              //alert(data.result.errorMessage);
              settime($("#register_page_send"));
              $('<div class="alert alert-warning fade in"><i class="fa-fw fa fa-warning"></i><strong>提醒！</strong> '+data.message+'</div>').appendTo($("#message_alert"));
            }else{
              $('<div class="alert alert-danger fade in"><i class="fa-fw fa fa-times"></i><strong>错误！</strong> '+data.message+'</div>').appendTo($("#message_alert"));
            }
          }
        });
      });

      $("#btn-save-common").click(function(e){
        if($("#authcode").val()==""){
          alert("请输入验证码");
          return;
        }
        if($("select[name=newPassword]").val()==""){
          alert("请输入新密码");
          return;
        }
        if($("#newPassword").val()!=$("#confirmPassword").val()){
          alert("输入的新密码与确认密码不一致");
          return;
        }
        save_from();
      });

      function save_from(){
        if(!confirm("确定提交保存吗？")){
          return ;
        }
        $("#btn-save-common").hide();
        $.mobile.loading( "show", {
          text: "正在保存，请稍后...",
          textVisible: true,
          theme: "b",
          textonly: false,
          html: ""
        });
        $.ajax({
          type: "POST",
          url: $("form#form-common").attr("action"),
          cache:false,
          dataType:"json",
          data: $("form#form-common").serialize(),
          success: function(data){
            hide();
            if(data.state == 1){
                alert(data.message);
                location.replace("<%=path%>/mp/adminlogin?openId=${openId}");

            }else{
                $("#btn-save-common").show();
                alert(data.message);
            }
          }
        });
      }
    });
  </script>
</head>
<body>
<div data-role="page" >
  <div data-role="header" data-position="fixed" data-theme="a">
    <h1 style="float:left;margin: 0 10px;"><i class="fa fa-user"></i> 忘记密码</h1>
    <a href="#" id="btn-save-common" class="ui-btn ui-btn-right ui-icon-check ui-corner-all ui-btn-icon-left">提交</a>
  </div><!-- /header -->
  <div class="ui-content jqm-content jqm-fullwidth" role="main">
    <form id="form-common" method="post"  action="updatePass" data-ajax="false">
      <div class="ui-field-contain">
        <label>手机号：</label>
        <span><input type="text" id="mobile" name="mobile" ></span>
      </div>
      <div class="ui-field-contain">
        <label>新密码：</label>
        <span><input type="password" id="newPassword" name="newPassword" ></span>
      </div>
      <div class="ui-field-contain">
        <label>确认新密码：</label>
        <span><input type="password" id="confirmPassword" name="confirmPassword" ></span>
      </div>
      <div class="ui-field-contain">
        <label>验证码：</label>
        <span>
          <input type="text" id="authcode" name="authcode" >
          <a href="#" id="btn-get-code" class="ui-btn">获取验证码</a>
        </span>
      </div>
      <div class="ui-field-contain">
        <section class="col col-12" id="message_alert">
        </section>
      </div>
    </form>
  </div><!-- /content -->
</div>
</body>
</html>
